﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MusicWorks.Service.Helpers;

namespace MusicWorks.Service
{
    public abstract class BaseServiceClass
    {
        readonly IRequestBroker _broker = null;

        public BaseServiceClass(IRequestBroker requestBroker)
        {
            _broker = requestBroker;
        }

        public BaseServiceClass() : this(BrokerHelper.Current) { }

        /// <summary>
        /// Gets the current broker helper.
        /// </summary>
        /// <value>The current broker helper.</value>
        protected IRequestBroker Broker
        {
            get { return this._broker; }
        }  
        
        /// <summary>
        /// Executes the broker requests.
        /// </summary>
        public virtual void ExecuteBrokerRequests()
        {
            if (this._broker.OperationCount > 0)
            {
                this._broker.Execute();
            }
        }           
    }
}
